#include <iostream>
#include <cstring>
using namespace std;
const int N = 1e6 + 10;

typedef long long LL;

struct mm
{
    LL day, l, r;
} dans[N];
LL room[N];
int n, m;

bool check(int mid)
{
    LL backup[N];
    LL sub[N] = {0};
    memcpy(backup, room, sizeof room);
    for (int i = 1; i <= mid; ++i)
    {
        LL day = dans[i].day;
        sub[dans[i].l] -= day;
        sub[dans[i].r + 1] += day;
    }
    // for(int i = 1; i <= n; ++i)
    // cout << sub[i] << ' ';
    // cout << endl;
    LL sum = 0;
    for (int i = 1; i <= n; ++i)
    {
        sum += sub[i];
        backup[i] += sum;
        // if(mid == 2) cout << backup[i] << ' ';
        if (backup[i] < 0)
            return false;
    }
    // cout << endl;
    return true;
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> room[i];
    for (int i = 1; i <= m; ++i)
        cin >> dans[i].day >> dans[i].l >> dans[i].r;
    int l = 1, r = m + 1;
    while (l < r)
    {
        int mid = (l + r) >> 1;
        if (check(mid))
            l = mid + 1;
        else
            r = mid;
    }
    if (r == m + 1)
        cout << 0 << endl;
    else
        cout << -1 << endl
             << l << endl;
    return 0;
}